package com.xy.weixin.tuling;


import com.xy.weixin.tuling.entity.BaseEntity;
import com.xy.weixin.tuling.entity.FlightEntity;
import com.xy.weixin.tuling.entity.InfoEntity;
import com.xy.weixin.tuling.entity.NewsEntity;
import com.xy.weixin.tuling.entity.TrainEntity;


public class TuLingRobot {

	/**
	 * @param args
	 */
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {
		TulingApiProcess process = new TulingApiProcess();
		BaseEntity baseEntity = process.getTulingResult("申通快递");
		if (baseEntity != null) {
			switch (baseEntity.getCode()) {
			case 100000:	//文本类数据
				System.out.println("Text:"+baseEntity.getText().trim());
				break;
			case 305000:	//列车
				BaseEntity<TrainEntity> trainEntity = (BaseEntity<TrainEntity>)baseEntity;
				System.out.println("Text:"+trainEntity.getCode());
				//detailurl:http://touch.qunar.com/h5/train/
				for(TrainEntity entity:trainEntity.getList()) {
					System.out.println("trainnum:"+entity.getTrainnum()+" start:"+entity.getStart()+" terminal:"+entity.getTerminal()+
							" starttime:"+entity.getStarttime()+" endtime:"+entity.getEndtime()+" detailurl:"+entity.getDetailurl()+" icon:"+entity.getIcon());
				}
				break;
			case 306000:	//航班
				BaseEntity<FlightEntity> flightEntity = (BaseEntity<FlightEntity>)baseEntity;
				System.out.println("Text:"+flightEntity.getCode());
				//detailurl:http://touch.qunar.com/h5/flight/
				for(FlightEntity entity:flightEntity.getList()) {
					System.out.println("flight:"+entity.getFlight()+" route:"+entity.getRoute()+" starttime:"+entity.getStarttime()+" endtime:"+entity.getEndtime()+
							" state:"+entity.getState()+" detailurl:"+entity.getDetailurl()+" icon:"+entity.getIcon());
				}
				break;
			case 200000:	//网址类数据
				//请点击 <a href="+baseEntity.getUrl()+">打开页面</a>
				System.out.println("Text:"+baseEntity.getText());
				System.out.println("Url:"+baseEntity.getUrl());
				break;	
			case 302000:	//新闻
				BaseEntity<NewsEntity> newsEntity = (BaseEntity<NewsEntity>)baseEntity;
				System.out.println("Text:"+newsEntity.getCode());
				for(NewsEntity entity:newsEntity.getList()) {
					System.out.println("article:"+entity.getArticle()+" source:"+entity.getSource()+" detailurl:"+entity.getDetailurl()+" icon:"+entity.getIcon());
				}
				break;
			case 308000:	//菜谱、视频、小说
				BaseEntity<InfoEntity> infoEntity = (BaseEntity<InfoEntity>)baseEntity;
				System.out.println("Text:"+infoEntity.getCode());
				for(InfoEntity entity:infoEntity.getList()) {
					System.out.println("name:"+entity.getName()+" info:"+entity.getInfo()+" detailurl:"+entity.getDetailurl()+" icon:"+entity.getIcon());
				}
				break;
			default:	//其他
				break;
			}
		}else {
			System.out.println("你说的太高深了哦！o(╯□╰)o");
		}
	}
}
